<template>
  <div id="log">
    <div class="row">
      <div class="col-md-12">
        <blockquote class="panel-primary small bg-info">
          <input type="text" v-model="baseUrl">
          <span v-text="logListUrl"></span>
          <span>&nbsp;接口访问日志</span>
        </blockquote>
      </div>
    </div>
    <div class="row">
      <div class="col-md-12">
        <table class="table table-striped table-bordered table-hover">
          <thead>
            <tr class="" >
              <th>ID</th>
              <th>模块</th>
              <th>目录</th>
              <th>控制器</th>
              <th>方法</th>
              <th>状态</th>
              <th>消息</th>
              <th>IP</th>
              <th>时间</th>
              <th>操作</th>
            </tr>
          </thead>
          <tbody>
            <tr v-for="log in list">
              <td>{{ log.id }}</td>
              <td>{{ log.module }}</td>
              <td>{{ log.dir }}</td>
              <td>{{ log.controller }}</td>
              <td>{{ log.action }}</td>
              <td>{{ log.result_status }}</td>
              <td>{{ log.result_msg }}</td>
              <td>{{ log.add_ip }}</td>
              <td>{{ log.add_time }}</td>
              <td><router-link :to="'/logDetail/' + log.id">详情</router-link></td>
            </tr>
            <tr>
              <td colspan="10" align="center">
                <page @clickPage="clickPage" :count="count" :page-number="pageNum" :this-page="thisPage"></page>
              </td>
            </tr>
          </tbody>
        </table>
      </div>
    </div>
  </div>
</template>
<script>
  import {baseUrl, logListUrl} from '../assets/js/setting.js'
  import page from './Page.vue'
  import bus from '../assets/js/bus.js'
  import mixin from '../assets/js/mixin.js'
  export default{
    data: () => {
      return {
        baseUrl: baseUrl,
        logListUrl: logListUrl,
        list: [],
        allPage: 0,
        count: 0,
        thisPage: 1,
        pageNum: 20
      }
    },
    created () {
      this.getList()
      bus.$on('changeBaseUrl', this.changeBaseUrl)
    },
    watch: {
      thisPage: function () {
        this.getList()
      }
    },
    mixins: [mixin],
    components: {page: page},
    methods: {
      // 设置页码
      clickPage (page) {
        this.thisPage = page
      },
      getList () {
        let loading = this.$loading({fullscreen: true, text: '正在载入数据...'})
        this.$http.get(this.baseUrl + this.logListUrl, {
          params: {
            p: this.thisPage,
            n: this.pageNum
          }
        })
        .then((res) => {
          loading.close()
          if (res.status === 200) {
            if (res.data.status === 1) {
              let re = res.data.res.res
              this.list = re.list
              this.allPage = re.allPage
              this.count = parseInt(re.count)
              this.thisPage = parseInt(re.thisPage)
            }
          }
        })
        .catch((err) => {
          loading.close()
          console.log('err', err)
        })
      }
    }
  }
</script>
<style scoped>
  #log{
    margin-top: 60px;
  }
</style>
